<template>
  <div class="home">
    <el-container style="border: 1px solid #eee">
      <el-header>
        <h1 style="margin: 0px 0px; width: 200px">宿舍管理系统</h1>
        <div style="flex: 1">
          <span>首页 / </span>
          <span>{{$store.state.userInfo.account}} </span>
          <span style="color: red">({{$store.state.userInfo.msg}})</span>
        </div>
        <!--        <el-breadcrumb separator="/">-->
        <!--          <el-breadcrumb-item :to="{ path: '/welcome' }">首页</el-breadcrumb-item>-->
        <!--          <el-breadcrumb-item><a href="/login">退出系统</a></el-breadcrumb-item>-->
        <!--          <el-breadcrumb-item>活动详情</el-breadcrumb-item>-->
        <!--        </el-breadcrumb>-->
        <el-avatar size="large" :src="require('../../img/6.jpg')"></el-avatar>
        <el-dropdown @command="handleCommand">
          <span class="el-dropdown-link">
            <i class="el-icon-arrow-down el-icon--right"></i>
          </span>
          <el-dropdown-menu slot="dropdown">
            <el-dropdown-item command="userInfo">个人信息</el-dropdown-item>
            <el-dropdown-item command="logout">注销</el-dropdown-item>
          </el-dropdown-menu>
        </el-dropdown>
      </el-header>
      <el-container>
        <el-aside width="200px">
          <el-menu @select="handleMenuSelected" :router="true">
            <el-menu-item
              v-for="item in menus"
              :class="{'is-active' : item.href == $store.state.menu_active}"
              :key="item.id"
              :index="item.href"
            >
              <i class="el-icon-setting"></i>
              <span slot="title">{{ item.title }}</span>
            </el-menu-item>
            <!--            <el-menu-item index="/dormAdminManager">-->
            <!--              <i class="el-icon-setting"></i>-->
            <!--              <span slot="title">宿舍管理员管理</span>-->
            <!--            </el-menu-item>-->
            <!--            <el-menu-item index="/stuManagement">-->
            <!--              <i class="el-icon-setting"></i>-->
            <!--              <span slot="title">学生管理</span>-->
            <!--            </el-menu-item>-->
            <!--            <el-menu-item index="/dormManagement">-->
            <!--              <i class="el-icon-setting"></i>-->
            <!--              <span slot="title">宿舍楼管理</span>-->
            <!--            </el-menu-item>-->
            <!--            <el-menu-item index="/absence">-->
            <!--              <i class="el-icon-setting"></i>-->
            <!--              <span slot="title">缺勤记录</span>-->
            <!--            </el-menu-item>-->
            <!--            <el-menu-item index="/modifyPassword">-->
            <!--              <i class="el-icon-setting"></i>-->
            <!--              <span slot="title">修改密码</span>-->
            <!--            </el-menu-item>-->
          </el-menu>
        </el-aside>

        <el-main>
          <router-view />
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script src="../../public/js/mock.js"></script>
<script>
// @ is an alias to /src
// import HelloWorld from '@/components/HelloWorld.vue';
import menusApi from "../http/menusApi";
import loginApi from "../http/loginApi";

export default {
  name: 'Home',
  data() {
    return {
      menus: [
        { id: 1, title: '首页', href: '/welcome.html', roles: '0,1,2' },
        {
          id: 2,
          title: '宿舍管理员管理',
          href: '/dormAdminManager.html',
          roles: '0,1'
        },
        {
          id: 3,
          title: '学生管理',
          href: '/students.html',
          roles: '0,1,'
        },
        {
          id: 4,
          title: '宿舍楼管理',
          href: '/dormManagement.html',
          roles: '0,1'
        },
        // { id: 5, title: '缺勤记录', href: '/absence.html', roles: '0,1' },
        // { id: 6, title: '修改密码', href: '/modifyPassword.html', roles: '0,1' }
      ]
    };
  },
  methods: {
    handleCommand(command) {
      this.$message('click on item ' + command);
      if (command == "logout"){
        loginApi.logout().then(res => {
          if (res.data.code == 200) {
            this.$message.info(res.data.msg);
            sessionStorage.clear();
            this.$router.replace("/login");
          }
        })
      }
    },
    handleMenuSelected(index,indexPath){
      this.$store.commit("SET_MENU_ACTIVE",index);
    }
  },
  created() {
    this.$store.dispatch('GET_DORMS_ACTIONS');
    this.$store.dispatch('GET_USERINFO_ACTIONS');
    menusApi.findAll().then(res => {
      if (res.data.code == 200){
        this.menus = res.data.data;
      }
    })
  }
};
</script>

<style>
.home {
  width: 100%;
  height: 100%;
  /*position: fixed;*/
}
.el-header {
  background-color: #b3c0d1;
  color: #333;
  text-align: left;
  display: flex;
  align-items: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}

.el-breadcrumb {
  position: fixed;
  transform: translate(150%, -260%);
}

/*.el-avatar {*/
/*  position: fixed;*/
/*  right: 5%;*/
/*  top: 2%;*/
/*}*/

.el-main {
  background-color: #e9eef3;
  color: #333;
  /*text-align: center;*/
  line-height: 160px;
}

body > .el-container {
  margin-bottom: 40px;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}
</style>
